package com.atguigu.crowd.mvc.config;

import com.atguigu.crowd.entity.Admin;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.util.Collection;

/**
 * 考虑到 User 对象中仅仅包含账号和密码，为了能够获取到原始的 Admin 对象，
 * 专门创建 这个类对 User 类进行扩展
 */
public class SecurityAdmin extends User {

    //封装原始的admin对象
    private Admin originalAdmin;



    public SecurityAdmin(Admin originalAdmin, Collection<? extends GrantedAuthority> authorities) {
        super(originalAdmin.getUserName(), originalAdmin.getUserPswd(), authorities);
        this.originalAdmin=originalAdmin;

        // 将原始 Admin 对象中的密码擦除
        this.originalAdmin.setUserPswd(null);
    }


    public Admin getOriginalAdmin() {
        return originalAdmin;
    }
}
